import {isEmpty, resetState} from '@/utils/index';
import {mapState, mapGetters, mapMutations, mapActions} from 'vuex';
import {Decrypt} from '@/utils/secret.js'

/*
用户模块的混合
 */
var user = {
    data (){
        return {
            ignoredPage:[
                'pages/system/login/index',
                'pages/index/index',
                'pages/index/guilde'
            ]
        };
    },
    computed:{
        // ...mapGetters(
        //     {
        //         user:'user/getUser'
        //     }
        // ),
        ...mapState({
            roleMenu:state=>state.user.roleMenu,
            forcedLogin:state=>state.user.forcedLogin,
            userData:state=>state.user.userData,
            hasLogin:state=>state.user.hasLogin,
            userDataForLogin:state=>state.user.userDataForLogin
        }),
		usernameSave(){
			return Decrypt(this.userDataForLogin.username)
		},
        meta(){
            return {
                label1:this.userData.name,
                label2:Decrypt(this.userData.username),
            }
        }
    },
    methods: {
        ...mapActions({
            logout: 'user/logout',
            login: 'user/login',
            setUserDataForLogin:'user/setUserDataForLogin'
        }),
        checkUserStatus(callback){
            var url = this.currentPage().route //当前页面url
            //console.log('url:',url==this.ignoredPage[0])
            //console.log('ignoredPage:',(this.ignoredPage.find(s=>s==url))==undefined)
            if ((this.ignoredPage.find(s=>s==url))==undefined){
                if(this.forcedLogin && !this.hasLogin){
					console.debug(222)
                    uni.navigateTo({
                        url: '/pages/system/login/index'
                    });
                    return;
                }
            }else {
                this.callbackSugar(callback);
            }
        }
    },
    /*
    当页面渲染完成，会去检查用户状态
     */
    // onReady(){
    //     var url = this.currentPage().route //当前页面url
    //     console.log('user Mixins onReady:',url)
    //     this.checkUserStatus();
    // }

}
export default user;
